package com.lee.thread;

class ThreadPrinter implements Runnable {

	private String name;
	
	private Object lockObj;
	
	
	public ThreadPrinter(String name, Object lockObj) {
		super();
		this.name = name;
		this.lockObj = lockObj;
	}

	@Override
	public void run() {
		int count = 20;
		while (count>0) {
			synchronized (lockObj) {
				lockObj.notify();
				System.err.print(name);
				count--;
				try {
					Thread.sleep(500);
					lockObj.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
		
		
	}
	
}

public class ThreadTest5 {
	public static void main(String[] args) throws InterruptedException {
		Object lockObj = new Object();
		ThreadPrinter t1 = new ThreadPrinter("A", lockObj);
		ThreadPrinter t2 = new ThreadPrinter("B", lockObj);
		new Thread(t1).start();
		Thread.sleep(100);
		new Thread(t2).start();
	}
}
